package com.kyzh.core.utils

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.gushenge.core.beans.CommunityBean
import com.gushenge.core.base.fragment.BaseFragment
import com.kyzh.core.pager.weal.community.CommunityFragment

/**
 *
 * @Author:         yu
 * @CreateDate:     2021/3/15 10:29
 */

fun ViewPager2.init(fragment: BaseFragment, fragments:ArrayList<Fragment>){
    this.offscreenPageLimit = ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT
    this.adapter=object :FragmentStateAdapter(fragment){
        override fun getItemCount()=fragments.size
        override fun createFragment(position: Int)=fragments[position]
    }
}

fun ViewPager2.init(fragment: FragmentActivity, fragments:ArrayList<Fragment>){
    this.offscreenPageLimit = ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT
    this.adapter=object :FragmentStateAdapter(fragment){
        override fun getItemCount()=fragments.size
        override fun createFragment(position: Int)=fragments[position]
    }
}

fun ViewPager2.initCommunity(fragment: FragmentActivity, id:String,fenlei: ArrayList<CommunityBean.Data.Fenlei>,name:String){
    this.offscreenPageLimit = ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT
    this.adapter=object :FragmentStateAdapter(fragment){
        override fun getItemCount()=fenlei.size
        override fun createFragment(position: Int)= CommunityFragment.newInstance(id,fenlei[position].type,name)
    }
}